package com.westvalley.common.action;

import com.jfinal.kit.JsonKit;
import com.jfinal.kit.LogKit;
import com.westvalley.common.action.result.ActionResult;
import com.westvalley.common.action.util.WorkFlowActionUtil;

import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

public abstract class BasisWe8Action implements Action {
	protected String mainTableName;

	public String execute(RequestInfo requestInfo) {
		ActionResult result = ActionResult.me(requestInfo);
		mainTableName = WorkFlowActionUtil.getDbMainTableName(requestInfo.getWorkflowid());
		try{
			result = executeResult(requestInfo);
		}catch (Exception e) {
			LogKit.error(">>>>>>>>>>>执行接口异常:",e);
			result = ActionResult.me(requestInfo, e);
		}
		LogKit.error(">>>>>>>>>result:"+JsonKit.toJson(result));
		return returnResult(requestInfo,result);
	}
	
	private String returnResult(RequestInfo requestInfo,ActionResult result){
		if(requestInfo!=null && result!=null){
			requestInfo.getRequestManager().setMessagecontent(result.getErrorMsg());
			return result.getReturnValue();
		}else{
			requestInfo.getRequestManager().setMessagecontent("result object is null!");
		}
		return FAILURE_AND_CONTINUE;
	}
	
	protected abstract ActionResult executeResult(RequestInfo requestInfo);
}
